package com.bangyu.monitor.core.mqtt;

import lombok.Data;

/**
 * @Auther: zhangxue
 * @Date: 19/4/12 16:08
 * @Description: 通道数据
 */
@Data
public class OneChSensor {
    /// 通道号
    private byte sensorCh;
    /// 传感器类型
    private int sensorTyp;
    /// 传感器值
    private float dValue;
    /// 输入字节数组构造单通道传感器
    /// <param name="data"></param>
    /// <param name="ch"></param>
    public OneChSensor(byte[] data, byte ch)
    {
        sensorTyp = data[0];
        byte dcmNum = (byte)(data[1] & 0x07);
        sensorCh = ch;
        byte syb = (byte)((data[1] >> 7) & 0x01);
        int val = (data[2] * 256 + data[3]);
        int value;
        if (syb == 1){
            value = (int)(val * -1);
        }
        else{
            value = val;
        }
        //  int value = val * syb;
        dValue = new Double((value / Math.pow(10,dcmNum))).floatValue();
    }




    public String ToString()
    {
        return null;
       // return ("通道号 : " + SensorCh.ToString("d") + "<>" + " 传感器类型: " + SensorTyp.ToString() + "<>" + "值 : " + Value.ToString("f1") + "\r\n");
    }
}
